package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags ="c端-套餐浏览接口" )
@RestController("UserSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 条件查询
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmeal",key = "#categoryId")//在方法执行前先查询缓存中是否有数据，如果有数据，则直接返回缓存数据；如果没有缓存数据，调用方法并将方法返回值放到缓存中
    @ApiOperation("分类id查询套餐")
    @GetMapping("/list")
    public Result<List<Setmeal>> listResult( Long categoryId){
        log.info("分类id查询套餐{}",categoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setStatus(StatusConstant.ENABLE);
        setmeal.setCategoryId(categoryId);
        List<Setmeal> setmealList=  setmealService.selectByCtageoryId(setmeal);
    return Result.success(setmealList);

    }

    @ApiOperation("根据套餐id查询包含的菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> listResult1(@PathVariable("id") Long id){
    List<DishItemVO> dishItemVOList=   setmealService.getById(id);
    return Result.success(dishItemVOList);
    }

}
